package com.ruoyi.system.listener;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.mapper.SysUserMapper;
import com.ruoyi.system.service.impl.SysUserServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener;
import org.flowable.engine.impl.el.FixedValue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 用户任务监听器
 *
 * @author KonBAI
 * @since 2023/5/13
 */
@Component(value = "userTaskListener")
@Slf4j
public class UserTaskListener implements ExecutionListener {

    /**
     * 注入字段（名称与流程设计时字段名称一致）
     */
     private FixedValue userId;

     @Autowired
     private SysUserMapper sysUserMapper;

    @Override
    public void notify(DelegateExecution delegateExecution) {
        String userId = "";
        if (null != delegateExecution.getVariableInstance("field104")) {
            userId = delegateExecution.getVariableInstance("field104").getValue().toString();
        }
        if (StringUtils.isNotEmpty(userId)) {
            int i = sysUserMapper.updateStatusById(Long.parseLong(userId));
            System.out.println(i);
        }
    }
}
